package cn.itcast.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*统一异常处理器*/
public class MyException implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        ModelAndView modelAndView = new ModelAndView();
        /*如果这个异常信息属于这个类型就*/
        if (ex instanceof UnauthorizedException){
            modelAndView.setViewName("forward:/unauthorized.jsp");
            return modelAndView;
        }
        modelAndView.addObject("msg","页面报错了请稍等");
        modelAndView.setViewName("error");
        return modelAndView;
    }
}
